<template>
  <el-dialog
    :model-value="show"
    title="申请详情"
    width="800px"
    append-to-body
    :before-close="handleClose"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    class="form-label-120"
    destroy-on-close
  >
    <DynamicsForm
      ref="DynamicsFormRef"
      :api="companyResourceFb_accountDetail"
      :params="formParams"
      :events="{ refreshEvent: refresh }"
    />
    <template #footer>
      <el-button type="primary" @click="toEdit">编辑</el-button>
      <el-button type="info" @click="handleClose">关闭</el-button>
    </template>
  </el-dialog>
</template>

<script setup>
import { companyResourceFb_accountDetail } from '@/api/resources';
import DynamicsForm from '@/components/DynamicsForm';

const props = defineProps({
  show: {
    type: Boolean,
    default: false
  },
  activeRow: {
    type: Object,
    default: () => {}
  }
});
const emit = defineEmits(['update:show', 'openToken', 'edit']);
const formParams = computed(() => {
  return { id: props.activeRow.id, view_type: 1 };
});

// 更新
function refresh() {
  emit('openToken');
}

// 关闭
function handleClose() {
  emit('update:show', false);
}

// 初始化表单
const DynamicsFormRef = ref();
watch(
  () => props.show,
  async val => {
    if (!val) return;
    await nextTick();
    DynamicsFormRef.value?.initFormList();
  }
);

function toEdit() {
  emit('edit', props.activeRow);
}

function initForm() {
  DynamicsFormRef.value?.initFormList();
}

defineExpose({ initForm });
</script>

<style lang="scss" scoped>
.refresh-btn {
  font-weight: bold;
  padding: 0;
  font-size: 20px;
  margin-left: 5px;
}
</style>
